
#ifndef __DESC_COMPILER_INFO_H__
#define __DESC_COMPILER_INFO_H__

#include "ds\ds_named_pair.h"

namespace dc {

enum VAR_TYPE_ENUM {
   VT_VOID,
   VT_USER,
   VT_DESC,
   VT_CONTAINER_FIRST,
   VT_ARRAY = VT_CONTAINER_FIRST,
   VT_SET,
};

struct VAR_TYPE {
   VAR_TYPE_ENUM  type;

   dsSTRID        name;    // VT_USER, VT_DESC
   int            typeId;  // VT_ARRAY, VT_SET

   VAR_TYPE(void)
      : type(VT_VOID)
      , typeId(VT_VOID)
   {}
};

using ds::TOKEN;

struct ATTRIB {
   ds::TOKEN            name;
   dsVECTOR<ds::TOKEN>  args;
};

class ATTRIB_CMP {
public:
   int  cmp      (const ATTRIB &a, const dsSTRID& b) const { return (a.name.value < b) ? -1 : ((b < a.name.value) ? 1 : 0); }
};

struct VAR {
   ds::TOKEN   name;
   int         type;
   ds::TOKEN   value;
   dsVECTOR<ATTRIB> attribs;
};

struct ENUM_INFO {
   dsSTRING          source;

   TOKEN             name;
   dsVECTOR<ATTRIB>  attribs;

   dsVECTOR<TOKEN>   values;
};

struct STATE_VAR_INFO {
   ds::TOKEN         name;
   ds::TOKEN         value;
};

struct STATE_INFO {
   ds::TOKEN         ownerDesc;
   ds::TOKEN         name;

   dsVECTOR<ATTRIB>  attribs;
   dsVECTOR<STATE_VAR_INFO> vars;
};

struct TYPE_INFO {
   dsSTRING          source;

   TOKEN             name;
   int               parentTypeId;
   dsVECTOR<ATTRIB>  attribs;

   dsVECTOR<VAR>     vars;
   dsVECTOR<STATE_INFO> states;

   TYPE_INFO(void)
      : parentTypeId(-1)
   {}
};

struct CONTEXT {
   dsSTRING            file;
   int                 line;

   dsVECTOR<TYPE_INFO> descs;
   dsVECTOR<TYPE_INFO> structs;
   dsVECTOR<ENUM_INFO> enums;
   dsVECTOR<VAR_TYPE>  types;

   CONTEXT(void)
      : line(0)
   {}

   int               AddType           (dsSTRID name);
   int               AddContainer      (VAR_TYPE_ENUM containerType, int elemTypeId);
   void              Clear             (void);
};

}

#endif // __DESC_COMPILER_INFO_H__